home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / domnames < prev    next >
Text File  |  1993-07-15  |  2KB  |  53 lines

  1. /*----------------------------------------------------------------------
  2.        Get the current host and domain names
  3.  
  4.     Args: hostname   -- buffer to return the hostname in
  5.           hsize      -- size of buffer above
  6.           domainname -- buffer to return domain name in
  7.           dsize      -- size of buffer above
  8.  
  9.   Result: The system host and domain names are returned. If the full host
  10.           name is akbar.cac.washington.edu then the domainname is
  11.           cac.washington.edu.
  12.  
  13. On Internet connected hosts this look up uses /etc/hosts and DNS to
  14. figure all this out. On other less well connected machines some other
  15. file may be read. If there is no notion of a domain name the domain
  16. name may be left blank. On a PC where there really isn't a host name
  17. this should return blank strings. The .pinerc will take care of
  18. configuring the domain names. That is, this should only return the
  19. native system's idea of what the names are if the system has such
  20. a concept.
  21.  ----*/
  22. void
  23. getdomainnames(hostname, hsize, domainname, dsize)
  24.     char *hostname, *domainname;
  25.     int   hsize, dsize;
  26. {
  27.     char           *dn, hname[MAX_ADDRESS+1];
  28.     struct hostent *he;
  29.  
  30.     gethostname(hname, MAX_ADDRESS);
  31.  
  32.     he = gethostbyname(hname);
  33.  
  34.     if(he == NULL && strlen(hname) == 0) {
  35.         strcpy(hostname, "");
  36.     } else if(he == NULL) {
  37.         strncpy(hostname, hname, hsize - 1);
  38.     } else {
  39.         strncpy(hostname, he->h_name, hsize-1);
  40.     }
  41.     hostname[hsize-1] = '\0';
  42.  
  43.  
  44.     if((dn = strindex(hostname, '.')) != NULL) {
  45.         strncpy(domainname, dn+1, dsize-1);
  46.     } else {
  47.         strncpy(domainname, hostname, dsize-1);
  48.     }
  49.     domainname[dsize-1] = '\0';
  50. }
  51.  
  52.  
  53.